package io.eleKing.boot.weather.controller;

import io.eleKing.boot.auth.annotation.Permission;
import io.eleKing.boot.common.enums.SysLogType;
import io.eleKing.boot.framework.annotation.Log;
import io.eleKing.boot.framework.page.Paging;
import io.eleKing.boot.framework.response.ApiResult;
import io.eleKing.boot.weather.dto.WeatherStationDto;
import io.eleKing.boot.weather.query.WeatherStationQuery;
import io.eleKing.boot.weather.service.WeatherStationService;
import io.eleKing.boot.weather.vo.WeatherStationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 自动站 控制器
 *
 * @author eleKing
 * @since 2025-04-15
 */
@Slf4j
@RestController
// 自动站
@RequestMapping("/admin/weatherStation")
public class WeatherStationController {

    @Autowired
    private WeatherStationService weatherStationService;

    /**
     * 添加自动站
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    // 添加自动站
    @PostMapping("/addWeatherStation")
    @Permission("weather:station:add")
    public ApiResult addWeatherStation(@Valid @RequestBody WeatherStationDto dto) {
        log.info("添加自动站：{}", dto);
        boolean flag = weatherStationService.addWeatherStation(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改自动站
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    // 修改自动站
    @PostMapping("/updateWeatherStation")
    @Permission("weather:station:update")
    public ApiResult updateWeatherStation(@Valid @RequestBody WeatherStationDto dto) {
        log.info("修改自动站：{}", dto);
        boolean flag = weatherStationService.updateWeatherStation(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除自动站
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    // 删除自动站
    @PostMapping("/deleteWeatherStation/{id}")
    @Permission("weather:station:delete")
    public ApiResult deleteWeatherStation(@PathVariable Long id) {
        log.info("删除自动站：{}", id);
        boolean flag = weatherStationService.deleteWeatherStation(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取自动站详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    // 获取自动站详情
    @PostMapping("/getWeatherStation/{id}")
    @Permission("weather:station:info")
    public ApiResult<WeatherStationVo> getWeatherStation(@PathVariable Long id) {
        log.info("获取自动站详情：{}", id);
        WeatherStationVo weatherStationVo = weatherStationService.getWeatherStationById(id);
        return ApiResult.success(weatherStationVo);
    }

    /**
     * 获取自动站分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    // 获取自动站分页列表
    @PostMapping("/getWeatherStationPage")
    @Permission("weather:station:page")
    public ApiResult<WeatherStationVo> getWeatherStationPage(@Valid @RequestBody WeatherStationQuery query) {
        log.info("获取自动站分页列表：{}", query);
        Paging<WeatherStationVo> paging = weatherStationService.getWeatherStationPage(query);
        return ApiResult.success(paging);
    }

}
